<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>首字母大写</title>
    <!-- 引入下载到本地 Vue.jsue.js -->
    <script src="./js/vue.js"></script>
</head>

<body>
    <div id="app">
        <h1>将字符串首字母大写</h1>
        <input type="text" v-model="str" placeholder="请输入一个字符串" />
        {{ str }}
        <p>{{ str | my-filter }}</p>
    </div>
    <!-- 用javascript脚本创建一个vue实例 -->
    <script type="text/javascript">
        // 注册
        Vue.filter("my-filter", function (value) {
            // 返回处理后的值
            if (!value) return "";
    value = value.toString();
    return value.split(' ').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ');
        });

        new Vue({
            el: "#app",
            data: {
                str: "",
            },
            //注册 局部 过滤器
            filters: {
                myFilter: function (value) {
                    // 返回处理后的值
                    if (!value) return "";
                    value = value.toString();
                    return value.charAt(0).toUpperCase() + value.slice(1);
                }
            }
        });



    </script>

</body>

</html>